extends Node

class Info:
	var id = ""
	var lv = 1
	var dir = ""
	var hide = false
	var type = sys.ItemType.EQUIP
	
var infoDs = {}
var infos = []
var rndPoolRsl = []
var rndPool: = RndPool.new()

var typeDs = {}

var rares = []

var utils = globalData.infoDs["g_azurlaneUtils"]

func _ready():
	pass

func loadInfo(dname, dir):
	var info = Info.new()
	info.id = dname
	infos.append(info)
	infoDs[info.id] = info
	info.dir = dir
	if dname.find("gun") > -1:
		info.type = sys.ItemType.GUN
	elif dname.find("torpedo") > -1:
		info.type = sys.ItemType.TORPEDO
	elif dname.find("equip") > -1:
		info.type = sys.ItemType.EQUIP	
	elif dname.find("plane") > -1:
		info.type = sys.ItemType.PLANE

	if dname.find("_rare_") > -1:
		rares.append(info.id)
		info.hide = true

	if dname.find("_ex_") > -1:
		info.hide = true

	if not info.hide:
		utils.dicAppend(typeDs, info.type, info)
	
func rndPoolRs():
	rndPool.clear()
	for i in rndPoolRsl:
		rndPool.addItem(infoDs[i], 1)

func reSet():
	infos.clear()
	infoDs.clear()
	rndPool.clear()
	rndPoolRsl.clear()

func rndGet(allowRare = false):
	var rnd = sys.rndRan(0, 100)
	if allowRare and rnd <= 10:
		return sys.rndListItem(rares)
	if rnd <= 18:
		return rndGetGun()
	elif rnd <= 36:
		return rndGetTorpedo()
	else:
		return rndGetEquip()

func rndGetTorpedo():
	return sys.rndListItem(typeDs.get(sys.ItemType.TORPEDO)).id

func rndGetGun():
	return sys.rndListItem(typeDs.get(sys.ItemType.GUN)).id

func rndGetEquip():
	return sys.rndListItem(typeDs.get(sys.ItemType.EQUIP)).id

enum EquipType{AD, AP, DEF}	

const ad = ["i_equip_1scjd", "i_equip_glgl", "i_equip_heavyAmmo", "i_equip_hkld", "i_equip_sg", "i_rare_equip_candyBullet", "i_equip_6crh", "i_equip_ciweidan", "i_equip_dainabaonengjn",
"i_equip_guliteshengjian"]
const ad2 = ["i_equip_ankanggan", "i_rare_equip_fi282"]
const adAll = ad + ad2
const ap = ["i_equip_cixingyulei", "i_equip_sg", "i_equip_steering", "i_equip_zhmk", "i_rare_equip_candyBullet", "i_equip_diandongydj"]
const ap2 = ["i_equip_98delay", "i_equip_lszdj", "i_rare_equip_repeater", "i_rare_equip_rndWord"]
const apAll = ap + ap2
const def = ["i_equip_fuhuo", "i_equip_fylgc", "i_equip_hjmc", "i_equip_huangyouyou", "i_equip_repairKit", "i_equip_vh", "i_equip_yeyaduoji", "i_equip_tuoluoyi"]
const def2 = ["i_equip_vc", "i_equip_zzzl", "i_rare_equip_liquidMetal"]
const defAll = def + def2
const air = ["i_equip_98delay", "i_equip_oilTank", "i_equip_yeyatansheqi", "i_rare_equip_100AirOil", "i_rare_equip_beacon", "i_rare_equip_liquidMetal", "i_equip_tancepinghengzz"]
const other = ["i_rare_equip_explorerMedal", "i_rare_equip_projector", "i_rare_equip_tianshizhiyu", "i_rare_equip_posundeyjg", "i_rare_equip_yonggandemmzz"]
const all = adAll + apAll + defAll + other

const ad3 = adAll + ["i_rare_equip_liquidMetal"]
const ap3 = apAll + ["i_rare_equip_liquidMetal"]

func rndGetEquipEx(type):
	match type:
		EquipType.AD:
			return sys.rndListItem(ad)
		EquipType.AP:
			return sys.rndListItem(ap)
		EquipType.DEF:
			return sys.rndListItem(def)

func rndGetByPrefer(prefer):
	match prefer:
		"ad":return sys.rndListItem(ad3)
		"ap":return sys.rndListItem(ap3)
		"air":return sys.rndListItem(air)
		"all":return sys.rndListItem(all)
		"t":return sys.rndListItem(defAll)

func checkItemType(item):
	if adAll.has(item.id):
		return "ad"
	elif def2.has(item.id):
		return "t"
	elif apAll.has(item.id):
		return "ap"
	elif air.has(item.id):
		return "air"
	else:
		return "all"